package com.kingwang.training.ooad.coffeemaker;

import com.kingwang.training.ooad.coffeemaker.goodway.impl.M4CoffeeMakerApi;
import com.kingwang.training.ooad.coffeemaker.goodway.impl.M4ContainmentVessel;
import com.kingwang.training.ooad.coffeemaker.goodway.impl.M4HotWaterSource;
import com.kingwang.training.ooad.coffeemaker.goodway.impl.M4UserInterface;
import com.kingwang.training.ooad.coffeemaker.hardware.api.CoffeeMakerApi;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CoffeeMakerApplication implements ApplicationRunner {

    public static void main(String[] args) {
        SpringApplication.run(CoffeeMakerApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        CoffeeMakerApi api = new M4CoffeeMakerApi();

        M4UserInterface ui = new M4UserInterface(api);
        M4HotWaterSource hotWaterSource = new M4HotWaterSource(api);
        M4ContainmentVessel containmentVessel = new M4ContainmentVessel(api);

        ui.init(hotWaterSource, containmentVessel);
        hotWaterSource.init(ui, containmentVessel);
        containmentVessel.init(ui, hotWaterSource);

        while (true) {
            ui.poll();
            hotWaterSource.poll();
            containmentVessel.poll();
        }
    }
}
